#include "locksystemdialog.h"
#include "ui_locksystemdialog.h"
#include "tools/aqp/aqp.hpp"
#include <QFile>
#include <QTextStream>

LockSystemDialog::LockSystemDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::LockSystemDialog)
{
    ui->setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint);
   // setModal(true);
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(doUnlock()));
}

LockSystemDialog::~LockSystemDialog()
{
    delete ui;
}
QString LockSystemDialog::getPasswordFromFile(const char* fileName)
{
    QFile file(fileName);
    QString password;
    if(file.open(QIODevice::ReadWrite))
    {
        QTextStream stream(&file);
        password = stream.readLine();
        file.close();
    }
    else {
        AQP::information(this,trUtf8("提示"),trUtf8("文件操作错误！"));
    }
    return password;
}
void LockSystemDialog::doUnlock()
{
    if (ui->lineEdit->text() == getPasswordFromFile("conf/password.txt")) {
        emit unlockSuccess();
        close();
    }
    else {
        AQP::information(this,trUtf8("提示"),trUtf8("密码不正确！"));
    }
}
